
import 'package:wallet/generated/l10n.dart';
import 'package:wallet/pages/discover_page.dart';
import 'package:wallet/pages/home_page.dart';
import 'package:wallet/pages/mine_page.dart';
import 'package:flutter/material.dart';
import 'package:wallet/pages/quotation_page.dart';

class MainPage extends StatefulWidget {
  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {

  var currentIndex = 0;

  List<BottomNavigationBarItem> getBottomNavItems(BuildContext context) {
    return [
      BottomNavigationBarItem(
        icon: Icon(Icons.home),
        title: Text(S.of(context).home),
      ),
      BottomNavigationBarItem(
        icon: Icon(Icons.equalizer),
        title: Text(S.of(context).quotation),
      ),
      BottomNavigationBarItem(
        icon: Icon(Icons.camera),
        title: Text(S.of(context).discover),
      ),
      BottomNavigationBarItem(
        icon: Icon(Icons.person),
        title: Text(S.of(context).mine),
      ),
    ];
  }

  final pages = [HomePage(), QuotationPage(), DiscoverPage(), MinePage()];

  void _changePage(int index) {
    if (index != currentIndex) {
      setState(() {
        currentIndex = index;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: pages[currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        items: getBottomNavItems(context),
        currentIndex: currentIndex,
        type: BottomNavigationBarType.fixed,
        onTap: (index) {
          _changePage(index);
        },
      ),
    );
  }
}
